package com.cn.wanxi.thread.timer;

import java.util.Timer;
import java.util.TimerTask;

public class MyTimer {
    public static void main(String[] args) {
        final int[] a = {0};
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(a[0]++);
                if (a[0] == 6) {
                    System.out.println("定时器取消");
                    timer.cancel();
                }
            }
        }, 4000, 2000);

    }

}
